package API.BigIntegerDome;

import java.math.BigInteger;

/**
 * ClassName:BigIntegerText002
 * Package:API.BigIntegerDome
 * Description:
 *
 * @Author:ZhangXin
 * @Create2023/1/31-15:22
 * @Version:v1.0
 */
public class BigIntegerText002 {
    /*
    * public BigInteger add(BigInteger val)  加法
    * public BigInteger subtract(BigInteger val) 减法
    * public BigInteger multiply(BigInteger val) 乘法
    * public BigInteger divide(BigInteger val) 除法,获取商
    * public BigInteger[] divideAndRemainder(BigInteger val) 除法,获取商和余数
    * public boolean equals(Object x) 比较是否相同
    * public BigInteger pow(int exponent) 次幂
    * public BigInteger max/min(BigInteger val) 返回较大值/较小值
    * public int intValue(BigInteger val) 转为int类型整数,超出范围数据有误*/
    public static void main(String[] args) {
        //1.创建两个BigInteger对象
        BigInteger bd1 = BigInteger.valueOf(10);
        BigInteger bd2 = BigInteger.valueOf(4);
//        //加法
//        BigInteger add = bd1.add(bd2);
//        System.out.println(add);
//        //减法
//        BigInteger subtract = bd1.subtract(bd2);
//        System.out.println(subtract);

        //除法,获取商和余数
        BigInteger[] arr = bd1.divideAndRemainder(bd2);
        System.out.println(arr.length);//2 商  余数
        System.out.println(arr[0]);//商
        System.out.println(arr[1]);//余数

        //public boolean equals(Object x) 比较是否相同
        boolean equals = bd1.equals(bd2);
        System.out.println(equals);//false

        //public BigInteger pow(int exponent) 次幂
        BigInteger pow = bd1.pow(2); //10 的 2 次方
        System.out.println(pow);

        //public BigInteger max/min(BigInteger val) 返回较大值/较小值
        BigInteger max = bd1.max(bd2);
        System.out.println(max);//10
        System.out.println(max == bd1);//true
        System.out.println(max == bd2);//false

        //public int intValue(BigInteger val) 转为int类型整数,超出范围数据有误
//        BigInteger bd6 = BigInteger.valueOf(2147183647L);
//        int i = bd6.intValue();
//        System.out.println(i);
        BigInteger bd6 = BigInteger.valueOf(2147183647L);
        long i = bd6.longValue();
        System.out.println(i);

    }
}
